/*
 * 添加角色交易
 * 参数   交易码：trancode=1022,角色名：name，备注:memo
 * 
 */

package org.ccams.tran;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.ccams.domain.TRole;
import org.ccams.util.Utils;

/**
 * 添加角色交易
 * @author liuguangshuai@gmail.com
 * @系统名称：定制化辅助生成制造系统
 */
public class Tran1022 extends AbstractJsonTran {

	@SuppressWarnings("unchecked")
	public void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String name = (String) request.getParameter("name");
		String memo = (String) request.getParameter("memo");
		name = (name != null) ? name : "";
		memo = (memo != null) ? memo : "";
		HashMap<String, Object> jsonMap = new HashMap<String, Object>();
		boolean success = false;
		String message = "";
		TRole t = new TRole();
		t.setName(name);
		t.setValid(0);
		t.setMemo(memo);
		//获得当期时间
		t.setAddDate(Utils.getCurDate());
		int i = getCcamsService().getTroleDao().insertTRole(t);
		if (i == 1) {
			success = true;
			message = "角色添加成功";
		} else {
			success = false;
			message = "角色添加失败";
		}
		jsonMap.put("success", success);
		jsonMap.put("message", message);
		json.putAll(jsonMap);
	}
}
